//
//  SDLCRButtonView.m
//  aimigene
//
//  Created by mac on 2019/3/12.
//  Copyright © 2019年 pony. All rights reserved.
//

#import "SDLCRButtonView.h"

@interface SDLCRButtonView ()

@property (strong, nonatomic) UIButton *leftBtn;
@property (strong, nonatomic) UILabel *titleLab;
@property (strong, nonatomic) UIButton *rightBtn;

@end

@implementation SDLCRButtonView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        
        [self initview];
    }
    return self;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLab.text = title;
}

- (void)initview {
    
    UIColor *gray_colr = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
    UIColor *green_colr = [UIColor colorWithRed:80/255.0 green:169/255.0 blue:181/255.0 alpha:1];
    UIColor *bg_colr = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1];

    self.backgroundColor = bg_colr;
    
    UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(30, 10, 50, 24)];
    self.leftBtn = leftbutton;
    leftbutton.backgroundColor = [UIColor clearColor];
    leftbutton.titleLabel.font = [UIFont systemFontOfSize:17];
    [leftbutton setTitle:kYQLS(@"取消") forState:UIControlStateNormal];
    [leftbutton setTitleColor:gray_colr forState:UIControlStateNormal];
    [leftbutton addTarget:self action:@selector(leftButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:leftbutton];
    
    
    UILabel *label = [[UILabel alloc] init];
    self.titleLab = label;
    label.center = self.center;
    label.font = [UIFont systemFontOfSize:17];
    label.text = kYQLS(@"标题");
    label.textColor = gray_colr;
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor clearColor];
    [self addSubview:label];
    
    UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 30 - 50, 10, 50, 24)];
    self.rightBtn = rightbutton;
    rightbutton.backgroundColor = [UIColor clearColor];
    rightbutton.titleLabel.font = [UIFont systemFontOfSize:17];
    [rightbutton setTitle:kYQLS(@"确定") forState:UIControlStateNormal];
    [rightbutton setTitleColor:green_colr forState:UIControlStateNormal];
    [rightbutton addTarget:self action:@selector(rightButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightbutton];
    
}

- (void)leftButtonClicked:(UIButton*)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SDLCRButtonLeftEvent)]) {
        [self.delegate SDLCRButtonLeftEvent];
    }
}

- (void)rightButtonClicked:(UIButton*)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(SDLCRButtonRightEvent)]) {
        [self.delegate SDLCRButtonRightEvent];
    }
}

@end
